package com.ruoyi.jdgl.kfgl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import java.io.InputStream;

import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.jdgl.kfgl.domain.Kfgl;
import com.ruoyi.jdgl.kfgl.service.IKfglService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客房管理Controller
 *
 * @author huacai
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/jdgl/kfgl")
public class KfglController extends BaseController {
    @Autowired
    private IKfglService kfglService;

    /**
     * 查询客房管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Kfgl kfgl) {
        startPage();
        List<Kfgl> list = kfglService.selectKfglList(kfgl);
        return getDataTable(list);
    }

    /**
     * 导出客房管理列表
     */
    @Log(title = "客房管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Kfgl kfgl) {
        List<Kfgl> list = kfglService.selectKfglList(kfgl);
        ExcelUtil<Kfgl> util = new ExcelUtil<Kfgl>(Kfgl.class);
        util.exportExcel(response, list, "客房管理数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Kfgl> util = new ExcelUtil<Kfgl>(Kfgl.class);
        util.importTemplateExcel(response, "客房管理数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "客房管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<Kfgl> util = new ExcelUtil<Kfgl>(Kfgl.class);
        InputStream inputStream = file.getInputStream();
        List<Kfgl> list = util.importExcel(inputStream);
        inputStream.close();
        int count = kfglService.batchInsertKfgl(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取客房管理详细信息
     */
    @GetMapping(value = "/{kfglId}")
    public AjaxResult getInfo(@PathVariable("kfglId") String kfglId) {
        return success(kfglService.selectKfglByKfglId(kfglId));
    }

    /**
     * 新增客房管理
     */
    @Log(title = "客房管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Kfgl kfgl) {
        return toAjax(kfglService.insertKfgl(kfgl));
    }

    /**
     * 修改客房管理
     */
    @Log(title = "客房管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Kfgl kfgl) {
        return toAjax(kfglService.updateKfgl(kfgl));
    }

    /**
     * 删除客房管理
     */
    @Log(title = "客房管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{kfglIds}")
    public AjaxResult remove(@PathVariable String[] kfglIds) {
        return toAjax(kfglService.deleteKfglByKfglIds(kfglIds));
    }
}
